﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TDDConsoleApp;

namespace TDDTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void Test0dBm()
        {
            WattDBCalculator wattdb = new WattDBCalculator();

            Watt expectedResult = new Watt(0.001);
            Watt actualResult = wattdb.WattAfterGain(new Watt(0.001), new Decibel(0));

            Assert.AreEqual(expectedResult.Level, actualResult.Level, delta: expectedResult.Level / 100);
        }

        [TestMethod]
        public void Test3dBm()
        {
            WattDBCalculator wattdb = new WattDBCalculator();

            Watt expectedResult = new Watt(0.002);
            Watt actualResult = wattdb.WattAfterGain(new Watt(0.001), new Decibel(3));

            Assert.AreEqual(expectedResult.Level, actualResult.Level, delta: expectedResult.Level / 100);
        }

        [TestMethod]
        public void TestUnits()
        {
            Watt oneW = new Watt(1);
            Decibel oneD = new Decibel(1);

            Assert.AreEqual("Watt(s)", oneW.Unit);
            Assert.AreEqual("dBm", oneD.Unit);

        }

        [TestMethod]
        public void TestCB()
        {
            WattDBCalculator wattdb = new WattDBCalculator();
            CBRadio cbradio = new CBRadio(new Watt(4));
            Assert.IsNotNull(cbradio.wattPower);

            Watt expectedResult = new Watt(36);
            Decibel actualResult = wattdb.WatttoDBm(cbradio.wattPower);

            Assert.AreEqual(expectedResult.Level, actualResult.Level, delta: expectedResult.Level / 100);
        }

        [TestMethod]
        public void TestCellPhone()
        {
            WattDBCalculator wattdb = new WattDBCalculator();
            CellPhone cellphone = new CellPhone(new Decibel(27));
            Assert.IsNotNull(cellphone.dBPower);

            double expectedResult = 0.5;
            Watt actualResult = wattdb.DBmtoWatt(cellphone.dBPower);

            Assert.AreEqual(expectedResult, actualResult.Level, delta: expectedResult / 100);
        }

        [TestMethod]
        public void TestdBLoss()
        {
            WattDBCalculator wattdb = new WattDBCalculator();

            Decibel expectedResult1 = new Decibel(-3);
            Decibel outputdB1 = new Decibel(24);
            Decibel inputdB1 = new Decibel(27);
            Decibel actualResult1 = wattdb.dBLoss(inputdB1, outputdB1);
            Assert.AreEqual(expectedResult1.Level, actualResult1.Level, delta: -expectedResult1.Level / 100);

            Decibel expectedResult2 = new Decibel(-6);
            Watt outputwatt1 = new Watt(1);
            Watt inputwatt1 = new Watt(4);
            Decibel actualResult2 = wattdb.dBLoss(inputwatt1, outputwatt1);
            Assert.AreEqual(expectedResult2.Level, actualResult2.Level, delta: -expectedResult2.Level / 100);

            Decibel expectedResult3 = new Decibel(3);
            Decibel outputdB3 = new Decibel(18);
            Watt inputwatt3 = new Watt(0.032);
            Decibel actualResult3 = wattdb.dBLoss(inputwatt3, outputdB3);
            Assert.AreEqual(expectedResult3.Level, actualResult3.Level, delta: expectedResult3.Level / 10);

            Decibel expectedResult4 = new Decibel(-5);
            Watt outputw4 = new Watt(100E-6);
            Decibel inputdB4 = new Decibel(-5);
            Decibel actualResult4 = wattdb.dBLoss(inputdB4, outputw4);
            Assert.AreEqual(expectedResult4.Level, actualResult4.Level, delta: -expectedResult4.Level / 10);

        }
    }
}
